from datetime import datetime
from http import HTTPStatus

import pytest
from service import client_parkings


@pytest.fixture
def data():
    return {
        "client_id": 1,
        "parking_id": 1,
    }


def test_create_client_parking_route(client, monkeypatch, data):
    mock_id = 678

    def mock_park_client(client_id, parking_id):
        return {
            "id": mock_id,
            "client_id": client_id,
            "parking_id": parking_id,
            "time_in": datetime.now(),
            "time_out": None,
        }

    monkeypatch.setattr(client_parkings, "park_client", mock_park_client)

    response = client.post("/client_parkings/", json=data)
    assert response.status_code == HTTPStatus.CREATED
    assert response.json == {
        "id": mock_id,
        "time_in": response.json.get("time_in"),
        "time_out": None,
        **data,
    }


def test_finish_client_parking_route(client, monkeypatch, data):
    def mock_end_parking(client_id, parking_id):
        return None

    monkeypatch.setattr(client_parkings, "end_parking", mock_end_parking)

    response = client.delete("/client_parkings/", json=data)
    assert response.status_code == HTTPStatus.NO_CONTENT
